package com.vueperson.vueperson.services;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class RunT01 implements Runnable {
    private int ticket = 5;
    private String name;
    public RunT01(String name) {
        this.name = name;
    }


    @Override
    public    void run() {
       method2();
        }



public void method2(){
    for( int x = 0 ; x < 100 ; x ++) {
        if(this.ticket > 0) {
            System.out.println("卖票，ticket = " +this.ticket --);
        }
    }
}

    public void method(){
        for(int x = 0; x < 10 ; x++) {
            System.out.println(this.name + "运行，x = " + x);
        }
        }

    public static void main(String[] args) throws InterruptedException, ExecutionException {
    /*   new Thread(new RunT01("线程A")).start() ;
     new Thread(new RunT01("线程B")).start();
        new Thread(new RunT01("线程C") ).start();
*/
        FutureTask futureTask=new FutureTask(new RunT02());
        new Thread(futureTask).start();
        System.out.println("线程返回值：" + futureTask.get());



       /* for( int x = 0; x < 3 ; x ++) {
            String title = "线程对象-" + x;
            Runnable runnable = () ->{
                for(int y = 0; y < 10 ; y ++) {
                    System.out.println(title + "运行，y = " + y);
                }
            };
            new Thread(runnable).start();
        }*/
    }

}
class RunT02 implements Callable<String>{

    @Override
    public String call() throws Exception {
        method();
        return "线程执行完毕！";
    }

    public void method(){
        for ( int x = 0 ; x < 10 ; x ++ ) {
            System.out.println("******线程执行，x = " + x);
        }
    }
}